package com.mxpio.erp.common.sales.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.inventory.entity.Warehouse;
import com.mxpioframework.jpa.annotation.DictAble;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author : wpp
 * @Datetime : 2023/4/11 15:07
 * @Desc :
 * @Modor :  Modifytime:
 * @modDesc :
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "v_mb_erp_sales_so_line")
@NoArgsConstructor
@AllArgsConstructor
@Schema(description="销售订单明细行视图")
public class SalesOrderLineVO implements DictAble, Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "LINE_NO_", updatable = false)
    @Schema(description = "行号")
    @Id
    private String lineNo;

    @Column(name = "BIZ_NO_", updatable = false)
    @Schema(description = "业务单号")
    @Id
    private String bizNo;

    @Column(name = "CLOSE_STATUS_")
    @Schema(description = "关闭状态")
    @Dict(dicCode="ERP_COMMON_CLOSE_STATUS")
    private String closeStatus;

    @Column(name = "SORT_")
    @Schema(description = "顺序号")
    private String sort;

    @Column(name = "ITEM_CODE_")
    @Schema(description = "物料代码")
    private String itemCode;

    @Column(name = "ITEM_NAME_")
    @Schema(description = "物料名称")
    private String itemName ;

    @Column(name = "ITEM_SPEC_")
    @Schema(description = "规格型号")
    private String itemSpec;

    @Column(name = "WH_CODE_")
    @Schema(description = "入库仓库")
    @Dict(dicCode = "whCode" ,dicEntity = Warehouse.class, dicText = "whName")
    private String whCode;

    @Column(name = "QUANTITY_")
    @Schema(description = "数量")
    private BigDecimal quantity;

    @Column(name = "LOT_NO_")
    @Schema(description = "批次号")
    private String lotNo;

    @Column(name = "UNIT_CODE_")
    @Schema(description = "单位编号")
    @Dict(dicCode="ERP_TECH_UNIT_CODE")
    private String unitCode;

    @Column(name = "DRAWING_NO_")
    @Schema(description = "图号")
    private String drawingNo;

    @Column(name = "ACTUAL_QUANTITY_")
    @Schema(description = "已核销数量")
    private BigDecimal actualQuantity;

    @Column(name = "REST_QUANTITY_")
    @Schema(description = "待核销数量")
    private BigDecimal restQuantity;

    @Column(name = "BPMN_STATUS_")
    @Schema(description = "主单审核状态")
    @Dict(dicCode = "ERP_COMMON_BPMN_STATUS")
    private String bpmnStatus;

    @Column(name = "BIZ_CLOSE_STATUS_")
    @Schema(description = "主单关闭状态")
    @Dict(dicCode="ERP_COMMON_CLOSE_STATUS")
    private String bizCloseStatus;

    @Column(name = "CREATE_BY", updatable = false)
    @Schema(description = "创建人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String createBy;

    @Column(name = "CREATE_DEPT", updatable = false)
    @Schema(description = "创建部门")
    @Dict(dicCode = "deptCode", dicEntity = Dept.class, dicText = "deptName")
    private String createDept;

    @Column(name = "UPDATE_BY")
    @Schema(description = "更新人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String updateBy;

    @Column(name = "CREATE_TIME", updatable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "创建时间")
    private Date createTime;

    @Column(name = "UPDATE_TIME")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "更新时间")
    private Date updateTime;


    @Column(name = "PN_CODE_")
    @Schema(description = "客户编号")
    private String pnCode;

    @Column(name = "PN_NAME_")
    @Schema(description = "客户名称")
    private String pnName;

    @Column(name = "DELIVER_DATE_")
    @Schema(description = "交付日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date deliverDate;
    @Transient
    private Map<String, String> textMap;

    public String putText(String key, String value) {
        if (textMap == null) {
            textMap = new HashMap<>();
        }
        return textMap.put(key, value);
    }
}
